/* 组件在 layout 布局文件中引用，全局通过redux控制 */

import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Modal, Button } from 'antd';
import { useNavigate } from 'react-router-dom';

import { setLoginOpen } from '@/reducers/main';
import styles from './index.module.scss';

const ModalLogin = (props) => {
    const navigate = useNavigate(),
        dispatch = useDispatch(),
        mainStore = useSelector(store => store.main);

    // 取消登录
    const onCancelLogin = () => {
        dispatch(setLoginOpen(false));
    };
    const toLogin = () => {
        onCancelLogin();
        navigate(`${BASEDIR}/login`);
    };

    return (
        <Modal
            className={styles['container']}
            open={mainStore.showLoginModal}
            onCancel={onCancelLogin}
            width={374}
            destroyOnClose={true}
            maskClosable={false}
            title="登录状态已过期"
            footer={null}
        >
            <div className={styles['header']}>登录状态已过期，登录后使用该功能</div>
            <div className={styles['footer']}>
                <Button onClick={onCancelLogin}>取消</Button>
                <Button type="primary" onClick={toLogin} className='custom-btn-primary'>登录</Button>
            </div>
        </Modal>
    )
}

export default ModalLogin;
